import { defineStore } from 'pinia'

export const useUsersStore = defineStore('users', {
    state: () => {
        const name = "张三"
        const age = 18
        const sex = "男"
        return { name, age, sex }
    },
    getters: {
        getAddAge: (state) => state.age + 100,
        // getter传参数
        getAge: (state) => {
            // 参数写在这里
            return (num: number) => state.age + num
        },
        ifZhangsan: (state) => {
            if (state.name != "张三") {
                return "现在不是张三了！！"
            } else {
                return "张三当家！"
            }
        },
        // 在getter中调用其他getter
        getNameAge(): string {
            return this.name + this.getAddAge
        }
    },
    actions: {
        saveName(name: string) {
            this.name = name
        }
    }
})